<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="房屋名称" prop="houseName">
        <el-input
          v-model="queryParams.houseName"
          placeholder="请输入房屋名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="户型" prop="houseType">
        <el-input
          v-model="queryParams.houseType"
          placeholder="请输入户型"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="装修" prop="houseFurnished">
        <el-select
          v-model="queryParams.houseFurnished"
          placeholder="房屋装修承度"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="dict in dict.type.sys_house_furnished"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="价格范围">
        <vue-input-range
          v-model="priceRange"
          size="middle"
          connect-text="-"
          pre-placeholder="最低价格"
          append-placeholder="最高价格"
        ></vue-input-range>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['entity:house:add']"
        >上架房源
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="houseList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="编号" align="center" prop="houseId"/>
      <el-table-column label="房屋名称" align="center" prop="houseName">
        <template slot-scope="scope">
          <router-link :to="'/system/rental-type/index/' + scope.row.houseId" class="link-type">
            <span>{{ scope.row.houseName }}</span>
          </router-link>
        </template>
      </el-table-column>
      <el-table-column label="面积(㎡)" align="center" prop="houseArea"/>
      <el-table-column label="租金/月" align="center" prop="rentalPrice"/>
      <el-table-column label="朝向" align="center" prop="houseTowards">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_house_towards" :value="scope.row.houseTowards"/>
        </template>
      </el-table-column>
      <el-table-column label="装修" align="center" prop="houseFurnished">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_house_furnished" :value="scope.row.houseFurnished"/>
        </template>
      </el-table-column>
      <el-table-column label="户型" align="center" prop="houseType"/>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="是否在租" align="center" prop="isRental">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_house_rental" :value="scope.row.isRental"/>
        </template>
      </el-table-column>
      <el-table-column label="发布时间" align="center" prop="createTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['entity:house:edit']"
            v-if="scope.row.isHandle == 0"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['entity:house:remove']"
            v-if="scope.row.isHandle == 1"
          >删除
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['entity:house:remove']"
            v-if="scope.row.isHandle == 0"
          >取消申请
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-house"
            @click="handleHouseApp(scope.row)"
            v-hasPermi="['domain:appointment:add']"
            v-if="scope.row.isRental == 1 && scope.row.isHandle == 1"
          >预约看房
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-check"
            @click="handleContractApp(scope.row)"
            v-hasPermi="['domain:contract:add']"
            v-if="scope.row.isRental == 1 && scope.row.isHandle == 1"
          >申请租房
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-chat-line-square"
            @click="checkComment(scope.row)"
            v-hasPermi="['domain:comment:list']"
            v-if="scope.row.isHandle == 1"
          >查看评论
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-chat-line-square"
            @click="userDetail(scope.row)"
            v-hasPermi="['domain:medium:query']"
            v-if="scope.row.isHandle == 0"
          >发布人详情
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-picture-outline"
            @click="checkHouseImg(scope.row)"
            v-hasPermi="['entity:house:query']"
          >查看房源图片
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-success"
            @click="releaseHouse(scope.row)"
            v-hasPermi="['entity:house:edit']"
            v-if="scope.row.isHandle == 0 && scope.row.status == 1"
          >发布该房源
          </el-button>
          <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)"
                       v-hasPermi="['domain:house:edit']" v-if="scope.row.isHandle == 1">
                <span class="el-dropdown-link">
                  <i class="el-icon-d-arrow-right el-icon--right"></i>更多
                </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="allotHouseMedium" icon="el-icon-key"
                                v-hasPermi="['domain:houseMedium:edit']">分配房屋中介
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 修改房屋信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="房屋名称" prop="houseName">
          <el-input v-model="form.houseName" placeholder="请输入房屋名称"/>
        </el-form-item>
        <el-form-item label="占地面积(㎡)" prop="houseArea">
          <el-input-number v-model="form.houseArea" placeholder="请输入占地面积"/>
        </el-form-item>
        <el-form-item label="租金/月" prop="rentalPrice">
          <el-input-number v-model="form.rentalPrice" placeholder="请输入租金"/>
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="朝向">
              <el-select v-model="form.houseTowards" placeholder="请选择朝向">
                <el-option
                  v-for="dict in dict.type.sys_house_towards"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="装修">
              <el-select v-model="form.houseFurnished" placeholder="请选择装修">
                <el-option
                  v-for="dict in dict.type.sys_house_furnished"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="户型" prop="houseType">
          <el-input v-model="form.houseType" placeholder="请输入户型"/>
        </el-form-item>
        <el-form-item label="楼层" prop="houseFloor">
          <el-input-number v-model="form.houseFloor" placeholder="请输入楼层"/>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加房屋信息对话框 -->
    <el-dialog :title="title" :visible.sync="addHouse" width="650px" append-to-body>
      <el-form ref="form" :model="houseInfo" :rules="rules" label-width="150px">
        <h4 class="el-form--inline">房屋信息</h4>
        <el-form-item label="房屋名称" prop="houseName">
          <el-input v-model="houseInfo.houseName" placeholder="请输入房屋名称"/>
        </el-form-item>
        <el-form-item label="占地面积(㎡)" prop="houseArea">
          <el-input-number v-model="houseInfo.houseArea" placeholder="请输入占地面积"/>
        </el-form-item>
        <el-form-item label="租金/月" prop="rentalPrice">
          <el-input-number v-model="houseInfo.rentalPrice" placeholder="请输入租金"/>
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="朝向">
              <el-select v-model="houseInfo.houseTowards" placeholder="请选择朝向">
                <el-option
                  v-for="dict in dict.type.sys_house_towards"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="装修">
              <el-select v-model="houseInfo.houseFurnished" placeholder="请选择装修">
                <el-option
                  v-for="dict in dict.type.sys_house_furnished"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="户型" prop="houseType">
          <el-input v-model="houseInfo.houseType" placeholder="请输入户型"/>
        </el-form-item>
        <el-form-item label="楼层" prop="houseFloor">
          <el-input-number v-model="houseInfo.houseFloor" placeholder="请输入楼层"/>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="houseInfo.remark" placeholder="请输入备注"/>
        </el-form-item>
        <h4 class="el-form--inline">租售类型</h4>
        <el-row>
          <el-col :span="12">
            <el-form-item label="付押类型">
              <el-select v-model="houseInfo.payType" placeholder="请选择">
                <el-option
                  v-for="dict in dict.type.sys_pay_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="整租/合租">
            <el-select v-model="houseInfo.entireOrShared" placeholder="请选择">
              <el-option
                v-for="dict in dict.type.entire_or_shared"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="招租人数" prop="needed" v-if="houseInfo.entireOrShared === '0'">
            <el-input-number v-model="houseInfo.needed" placeholder="请输入招租人数"/>
          </el-form-item>
          <el-form-item label="已租人数" prop="rented" v-if="houseInfo.entireOrShared === '0'">
            <el-input-number v-model="houseInfo.rented" placeholder="请输入已租人数"/>
          </el-form-item>
          <el-col v-if="houseInfo.entireOrShared === '0'">
            <el-form-item label="合租要求" prop="shareRequest">
              <el-input v-model="houseInfo.shareRequest" placeholder="请输入合租要求"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="起租时长要求(月)" prop="rentalRequest">
          <el-input-number v-model="houseInfo.rentalRequest" placeholder="请输入起租月份"/>
        </el-form-item>
        <h4 class="el-form--inline">配置家具</h4>
        <el-form-item label="家具">
          <el-select v-model="houseInfo.supports" multiple placeholder="请选择配套家具">
            <el-option
              v-for="dict in dict.type.sys_house_support"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <h4 class="el-form--inline">不动产权证</h4>
        <el-form-item prop="estate">
          <el-upload
            action="#"
            :http-request="estateUpload"
            :on-change="handleEstateChange"
            :on-preview="handlePreview"
            :auto-upload="false"
            :show-file-list="false"
            ref="estate"
            accept="image/*"
          >
            <i class="el-icon-plus"><img v-if="options.estate" :src="options.estate" height="200" width="200"></i>
          </el-upload>
        </el-form-item>
        <h4 class="el-form--inline">房源图片</h4>
        <el-form-item prop="houseImg">
          <el-upload
            action="#"
            :http-request="houseImgUpload"
            :show-file-list="false"
            :on-change="handleHoseImgChange"
            :on-preview="handlePreview"
            :auto-upload="false"
            ref="houseImg"
            accept="image/*"
          >
            <i class="el-icon-plus"><img v-if="options.houseImage" :src="options.houseImage" height="200"
                                         width="200"></i>
          </el-upload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!--添加预约看房信息-->
    <el-dialog :visible.sync="addHouseApp" :title="title">
      <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">
        <el-form-item label="房屋编号" prop="houseId">
          <el-input v-model="formData.houseId" disabled/>
        </el-form-item>
        <el-form-item label="预约时间选择" prop="appTime">
          <el-date-picker v-model="formData.appTime" type="datetime"
                          format="yyyy-MM-dd HH:mm:ss"
                          value-format="yyyy-MM-dd HH:mm:ss"
                          :style="{width: '100%'}"
                          :picker-options="pickerOptions"
                          placeholder="请选择预约时间" clearable></el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="cancel">取消</el-button>
        <el-button type="primary" @click="handelConfirm">提交</el-button>
      </div>
    </el-dialog>

    <!-- 查看中介信息对话框 -->
    <el-dialog :title="title" :visible.sync="mediumDetail" width="650px" append-to-body>
      <el-form ref="form" :model="user" label-width="150px">
        <el-form-item label="中介用户名" prop="userName">
          <el-input v-model="user.userName" disabled/>
        </el-form-item>
        <el-form-item label="中介昵称" prop="nickName">
          <el-input v-model="user.nickName" disabled/>
        </el-form-item>
        <el-form-item label="中介电话" prop="phone">
          <el-input v-model="user.phone" disabled/>
        </el-form-item>
        <el-form-item label="中介个人证件" prop="documents">
          <el-image :src="user.documents" style="width: 350px; height: 250px"/>
        </el-form-item>
        <el-form-item label="不动产权证" prop="documents">
          <el-image :src="options.estate" style="width: 350px; height: 250px"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 房源图片对话框 -->
    <el-dialog :title="title" :visible.sync="openHouseImg" width="650px" append-to-body>
      <el-image :src="options.houseImage"/>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {
  listHouse,
  getHouse,
  delHouse,
  addHouse,
  updateHouse,
  addHouseAppointment,
  userContractApp, mediumUserDetail, uploadEstate, adminReleaseHouse, uploadHouseImg
} from "@/api/system/house";
import modal from "@/plugins/modal";

export default {
  name: "House",
  dicts: ['sys_house_towards', 'sys_house_furnished', 'sys_house_rental', 'sys_normal_disable', 'entire_or_shared', 'sys_pay_type', 'sys_house_support'],
  data() {
    return {
      pickerOptions: {
        disabledDate: (time) => {
          return time.getTime() < Date.now() - 8.64e7;
        },
      },
      // 遮罩层
      loading: true,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 房屋信息表格数据
      houseList: [],
      //租金范围
      priceRange: [],
      //出租价格
      rentalPrice: 'RentalPrice',
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //是否显示添加层
      addHouse: false,
      //是否显示预约看房层
      addHouseApp: false,
      //是否显示房源图片层
      openHouseImg: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        houseName: null,
        houseFurnished: null,
        houseType: null,
        isRental: null,
        isHandle: null,
        status: null
      },
      options: {
        estate: null, //不动产权证的地址
        houseImage: null, //房源图片
        houseId: null, //添加房屋信息成功后返回的房屋编号
      },
      user: {},
      //中介信息弹出层
      mediumDetail: false,
      // 表单参数
      form: {},
      //预约看房表单参数
      formData: {
        houseId: null,
        appTime: null,
        remark: undefined,
      },
      //添加房屋信息参数
      houseInfo: {},
      // 表单校验
      rules: {
        houseName: [
          {required: true, message: "房屋名称不能为空", trigger: "blur"},
          {min: 4, max: 25, message: '用户名称长度必须介于 4 和 25 之间', trigger: 'blur'}
        ],
        houseArea: [
          {required: true, message: "房屋面积不能为0", trigger: "blur"},
        ],
        rentalPrice: [
          {required: true, message: "租金不能为0", trigger: "blur"},
        ],
        houseFloor: [
          {required: true, message: "房屋面积不能为0", trigger: "blur"}
        ],
        houseType: [
          {required: true, message: "请输入房屋户型", trigger: "blur"}
        ],
        rentalRequest: [
          {required: true, message: "起租时长不能为0", trigger: "blur"}
        ],
        shareRequest: [
          {required: true, message: "房屋名称不能为空", trigger: "blur"},
          {min: 5, message: '合租要求不能小于5个字', trigger: 'blur'}
        ],
        needed: [
          {required: true, message: "请输入招租人数", trigger: "blur"},
        ],
        rented: [
          {required: true, message: "请输入已租人数", trigger: "blur"},
        ],
        app_time: [{
          required: true,
          message: '请选择时间选择',
          trigger: 'change'
        }],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询房屋信息列表 */
    getList() {
      this.loading = true;
      const url = window.location.pathname;
      const accessPath = url.substr(url.lastIndexOf("/"), url.length);
      //判断当前页面
      switch (accessPath) {
        //审核房源列表,待处理且停用的房源
        case "/handleHouse":
          this.queryParams.isHandle = 0;
          this.queryParams.status = 1;
          break;
        //房源列表,已发布且启用的房源
        case "/houses":
          this.queryParams.isHandle = 1;
          this.queryParams.status = 0;
          break;
        default:
          break;
      }
      listHouse(this.addPriceRange(this.queryParams, this.priceRange, this.rentalPrice)).then(response => {
        this.houseList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.addHouse = false;
      this.addHouseApp = false;
      this.mediumDetail = false;
      this.openHouseImg = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        houseId: null,
        houseName: null,
        houseArea: null,
        houseTowards: null,
        houseFurnished: 0,
        houseType: null,
        houseFloor: null,
        createTime: null,
        updateTime: null,
        remark: null,
        status: "0",
      };
      this.formData = {
        app_time: null,
        remark: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.judgePrice();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.priceRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.houseId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.addHouse = true;
      this.title = "添加房屋信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const houseId = row.houseId || this.ids
      getHouse(houseId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改房屋信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.houseId != null) {
            updateHouse(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            let houseInfo = this.houseInfo;
            let houseImg = this.options.houseImage;
            let estate = this.options.estate;
            this.$modal.confirm("发布审核的房源信息不可再修改,房源信息是否确认无误?").then(function () {
              if (houseImg == undefined || houseImg == null && houseImg == '') {
                modal.msgError("请上传房源图片");
              } else if (estate == undefined || estate == null && estate == '') {
                modal.msgError("请上传不动产权证");
              } else {
                return addHouse(houseInfo);
              }
            }).then(response => {
              this.options.houseId = response.houseId;
              this.$refs.estate.submit();
              this.$refs.houseImg.submit();
              this.$modal.msgSuccess("发布成功,等待管理员审核发布");
              this.addHouse = false;
              this.$refs.upload.clearFiles();//清空
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const houseIds = row.houseId;
      this.$modal.confirm('是否确认删除房屋信息编号为"' + houseIds + '"的数据项？').then(function () {
        return delHouse(houseIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    //判断价格范围
    judgePrice() {
      if (this.priceRange === 0) {
        this.getList();
      } else {
        //获取最大价格和最小价格判断
        let min = this.priceRange[0];
        let max = this.priceRange[1];
        if (min < max || min === undefined || max === undefined) {
          this.getList();
        } else {
          modal.msgError("最小价格不能大于最大价格!!!")
        }
      }
    },
    // 更多操作触发
    handleCommand(command, row) {
      switch (command) {
        case "allotSupport":
          this.allotSupport(row);
          break;
        case "allotHouseMedium":
          this.allotHouseMedium(row);
          break;
        default:
          break;
      }
    },
    //分配家具
    allotSupport(row) {
      const houseId = row.houseId;
      this.$router.push("/system/support-allot/support/" + houseId);
    },
    //分配房屋中介
    allotHouseMedium(row) {
      const houseId = row.houseId;
      this.$router.push("/system/house-allot/medium/" + houseId)
    },
    //展示预约看房表单
    handleHouseApp(row) {
      this.reset();
      this.formData.houseId = row.houseId;
      this.addHouseApp = true;
      this.title = "添加房屋信息";
    },
    //提交预约看房信息
    handelConfirm() {
      this.$refs['elForm'].validate(valid => {
        if (valid) {
          addHouseAppointment(this.formData).then(response => {
            this.$modal.msgSuccess("发送预约消息成功");
            this.addHouseApp = false;
            this.getList();
          });
        }
      })
    },
    //租客租房申请
    handleContractApp(row) {
      //发送userId和houseId,返回信息申请成功,等待中介处理
      this.$modal.confirm("确认要申请租赁该房屋吗").then(function () {
        return userContractApp(row.houseId);
      }).then(() => {
        this.$modal.msgSuccess("申请信息已发送,等待中介生成合同");
      })
    },
    //用户查看该房源评论
    checkComment(row) {
      const houseId = row.houseId;
      this.$router.push("/system/house-comment/house/" + houseId);
    },
    //查看房屋发布人详情
    userDetail(row) {
      mediumUserDetail(row.houseId).then(response => {
        //个人证件和不同产权证
        this.user = response.user;
        this.user.documents = process.env.VUE_APP_BASE_API + response.user.documents;
        this.options.estate = process.env.VUE_APP_BASE_API + response.medium.estate;
        console.log(this.user)

        //打开房屋中介弹出框
        this.mediumDetail = true;
        this.title = "房屋发布人详情信息"
      })
    },
    //查看房源图片
    checkHouseImg(row) {
      getHouse(row.houseId).then(response => {
        this.options.houseImage = process.env.VUE_APP_BASE_API + response.data.houseImg;
        this.openHouseImg = true;
        this.title = '房源图片';
      })
    },
    handlePreview(file) {
      console.log(file);
    },
    handleEstateChange(file, fileList) {
      console.log(file)
      if (file.raw.type.indexOf("image/") === -1) {
        this.$modal.msgError("文件格式错误，请上传图片类型,如：JPG，PNG后缀的文件。");
      } else {
        const reader = new FileReader();
        reader.readAsDataURL(file.raw);
        reader.onload = () => {
          this.options.estate = reader.result;
        };
      }
    },
    handleHoseImgChange(file, fileList) {
      console.log(file)
      if (file.raw.type.indexOf("image/") === -1) {
        this.$modal.msgError("文件格式错误，请上传图片类型,如：JPG，PNG后缀的文件。");
      } else {
        const reader = new FileReader();
        reader.readAsDataURL(file.raw);
        reader.onload = () => {
          this.options.houseImage = reader.result;
        };
      }
    },
    // 覆盖默认的上传行为,房产证
    estateUpload(item) {
      let formData = new FormData();
      formData.append("estatefile", item.file);
      formData.append("houseId", this.options.houseId);
      uploadEstate(formData).then(response => {
        this.options.estate = process.env.VUE_APP_BASE_API + response.imgUrl;
      });
    },
    // 覆盖默认的上传行为,房源图片
    houseImgUpload(item) {
      let formData = new FormData();
      formData.append("houseImg", item.file);
      formData.append("houseId", this.options.houseId);
      uploadHouseImg(formData).then(response => {
        this.options.houseImage = process.env.VUE_APP_BASE_API + response.imgUrl;
      });
    },
    //管理员审核后正式发布房源
    releaseHouse(row) {
      let house = row;
      this.$modal.confirm("审核发布之后无法修改,是否正式发布该房源?").then(function () {
        return adminReleaseHouse(house);
      }).then(() => {
        this.$modal.msgSuccess("房源信息发布成功!!");
        this.getList();
      }).catch(() => {
      })
    }
  }
};
</script>
